package com.ai.controller.reviewed;

import java.util.Calendar;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ai.common.controller.BaseController;
import com.ai.common.exception.AlikAssert;
import com.ai.common.model.Result;
import com.ai.mmd.reviewed.dto.DlxxDTO;
import com.ai.service.reviewed.model.DlxxModel;
import com.ai.service.reviewed.service.IDlxxService;

/**
 * 会员信息审核 Created by renbangjie on 16/6/25.
 */
@RequestMapping("dlxx")
@Controller("com.ai.controller.reviewed.DlxxController")
public class DlxxController extends BaseController {
	
	/**
     * 冻结设置
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("djset")
    public Result djset(@ModelAttribute DlxxDTO dlxxDTO) throws Exception {
        AlikAssert.isNotNull(dlxxDTO, "参数异常.");
        AlikAssert.isNotNull(dlxxDTO.getId(), "参数异常.");
        AlikAssert.isNotNull(dlxxDTO.getDjlx(), "参数异常.");
        Result rs = new Result(true);
        
        //计算冻结结束时间
        if (dlxxDTO.getSfdj()==1) {
        	Calendar calendar = Calendar.getInstance();
            Date date = new Date(System.currentTimeMillis());
            calendar.setTime(date);
            switch (dlxxDTO.getDjlx()) {
    		case 1:
    			//一周
    			calendar.add(Calendar.WEEK_OF_YEAR, 1);
    			date = calendar.getTime();
                dlxxDTO.setDjjssj(date);
    			break;
    		case 2:
    			//一月
    			calendar.add(Calendar.MONTH, 1);
    			date = calendar.getTime();
                dlxxDTO.setDjjssj(date);
    			break;
    		case 3:
    			//半年
    			calendar.add(Calendar.MONTH, 6);
    			date = calendar.getTime();
                dlxxDTO.setDjjssj(date);
    			break;
    		case 4:
    			//一年
    			calendar.add(Calendar.YEAR, 1);
    			date = calendar.getTime();
                dlxxDTO.setDjjssj(date);
    			break;
    		case 5:
    			//永久
    			break;
    		default:
    			break;
    		} 
		} 
        
        DlxxModel dlxxModel = new DlxxModel();
        BeanUtils.copyProperties(dlxxDTO, dlxxModel);
        dlxxModel.setGxsj(new Date());
        idlxxService.updateByPrimaryKey(dlxxModel);
        return rs;
    }

	@Resource(name = "idlxxService")
	private IDlxxService idlxxService;

}
